package com.typhoon.spring_shiro.controller.zxing;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.typhoon.spring_shiro.controller.BaseController;
import com.typhoon.spring_shiro.utils.CommonUtils;
import com.typhoon.spring_shiro.utils.ZxingUtil;
/**
 * 二维码工具
 * 
 * @author Typhoon
 * @date 2017-07-06 15:34
 * @since V1.2.9
 */
@Controller
@RequestMapping("zxing")
public class ZxingController extends BaseController {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(ZxingController.class);
	
	
	@RequestMapping(value = "/encode.do")
	public void encode(@RequestBody Map<String, Object> params,HttpServletRequest request, HttpServletResponse response) {
		try {
			response.setContentType("image/jpeg;charset=utf-8" );
			response.setHeader("Pragma", "No-cache");
			response.setHeader("Cache-Control", "no-cache");
			response.setDateHeader("Expires", 0L);
			ZxingUtil.encode(CommonUtils.evalString(params.get("contents")), 300, 300, response.getOutputStream());
		} catch (Exception e) {
			LOGGER.error("",e);
		}
	}

}
